<template>
  <el-card>
    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div ref="box" style="width: 80%;height:400px;"></div>
  </el-card>
</template>

<script>
import Echarts from 'echarts'
export default {
  mounted() {
    this.getechars()
  },
  methods: {
    getechars() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = Echarts.init(this.$refs.box)

      // 指定图表的配置项和数据
      var option = {
        title: {
          text: '折线图堆叠'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['销售总量', '销售额']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '销售总量',
            type: 'line',
            stack: '总量',
            data: []
          },
          {
            name: '销售额',
            type: 'line',
            stack: '总量',
            data: []
          }
        ]
      }

      // 使用刚指定的配置项和数据显示图表。
      // myChart.setOption(option)
      this.$emit('datalist', { myChart, option })
    }
  }
}
</script>

<style lang="less" scoped></style>
